package algorithm;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class T00380 {
    public static void main(String[] args) {
        System.out.println(new RandomizedSet().getRandom());
    }

    static class RandomizedSet {

        private Map<Integer, Object> map;
        private static final Object OBJ = new Object();
        private Random random = new Random();

        public RandomizedSet() {
            map = new HashMap<>();
        }

        public boolean insert(int val) {
            if (map.containsKey(val)) {
                return false;
            }
            map.put(val, OBJ);
            return true;
        }

        public boolean remove(int val) {
            if (!map.containsKey(val)) {
                return false;
            }
            map.remove(val);
            return true;
        }

        public int getRandom() {
            Integer[] keys = map.keySet().toArray(new Integer[0]);
            int i = random.nextInt(keys.length);
            return keys[i];
        }
    }
}
